//https://leetcode.cn/problems/subarray-sum-equals-k/

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        int sum = 0, ret = 0;
        hash[0] = 1;
        for (auto e : nums)
        {
            sum += e;
            if (hash.count(sum - k))
                ret += hash[sum - k];
            hash[sum]++;
        }

        return ret;

    }
};